﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
//using System.Windows.Forms;

namespace DockSample
{
    public class HighOrderObjectDiagram : ObjectDiagram
    {
        //private List<OriginalDiagram> diagramList = new List<OriginalDiagram>();
        private bool hasModelForm = false;
        private ObjectModelForm newModelForm = null;
        public string newModelFormId=null;
        
        
        //####################################################################################
        public HighOrderObjectDiagram(Point point, int width = 160, int height = 160)
            : base(point, width, height)
        {
            name = "HighObject";
        }
        //绘图函数
        //************************************************************************************
        public override void Drawing(Graphics g, DummyModelForm m)
        {
       
            Rectangle bodyRect = new Rectangle(upLeftpoint.X, upLeftpoint.Y, width / 2, height);
            Rectangle attributeRect = new Rectangle(upLeftpoint.X + width / 2, upLeftpoint.Y + 2 * height / 21, width / 2, 5 * height / 21);
            Rectangle methodRect = new Rectangle(upLeftpoint.X + width / 2, upLeftpoint.Y + 8 * height / 21, width / 2, 5 * height / 21);
            Rectangle NFRRect = new Rectangle(upLeftpoint.X + width / 2, upLeftpoint.Y + 14 * height / 21, width / 2, 5 * height / 21);

            g.DrawRectangle(pen, bodyRect);
            g.DrawRectangle(pen, attributeRect);
            g.DrawRectangle(pen, methodRect);
            g.DrawRectangle(pen, NFRRect);

            drawingAttributes(g, attributeRect);
            drawingMethods(g, methodRect);
            drawingNFR(g, NFRRect);

            base.Drawing(g, m);
        
        
        }
        //************************************************************************************

        public bool HasModelForm
        {
            get{return hasModelForm;}
            set{hasModelForm = value;}
        }

        public ObjectModelForm NewModelForm
        {
            get{ return newModelForm;}
            set{newModelForm = value;}
        }

        private void drawingAttributes(Graphics g, Rectangle attributeRect)
        {
            StringBuilder attrShowString = new StringBuilder();
            foreach (Attribute attr in AttributeList)
            {
                attrShowString.AppendLine(attr.getShowString());
            }
            g.DrawString(attrShowString.ToString(), drawFont, drawBrush, attributeRect);
        }

        private void drawingMethods(Graphics g, Rectangle methodRect)
        {
            StringBuilder methodShowString = new StringBuilder();
            foreach (Method method in MethodList)
            {
                methodShowString.AppendLine(method.getShowString());
            }
            g.DrawString(methodShowString.ToString(), drawFont, drawBrush, methodRect);
        }

        private void drawingNFR(Graphics g, Rectangle methodRect)
        {
            StringBuilder NFRShowString = new StringBuilder();
            if (ObjectNFRList.Count != 0)
            {
                NFRShowString.AppendLine("O_" + name + ":[" + getNFRListString(ObjectNFRList) + "]");
            }

            foreach (Attribute attr in AttributeList)
            {
                if (attr.AttributeNFRList!=null)
                {
                    if (attr.AttributeNFRList.Count != 0)
                    {
                        NFRShowString.AppendLine("A_" + attr.AttributeName + ":[" + getNFRListString(attr.AttributeNFRList) + "]");
                    }
                }
                
            }

            foreach (Method method in MethodList)
            {
                if (method.MethodNFRList!=null)
                {
                    if (method.MethodNFRList.Count != 0)
                    {
                        NFRShowString.AppendLine("M_" + method.MethodName + ":[" + getNFRListString(method.MethodNFRList) + "]");
                    }
                }

               
            }

            g.DrawString(NFRShowString.ToString(), drawFont, drawBrush, methodRect);
        }
    }
}
